<!DOCTYPE html>
<html>
<head>
    <include file="Include:meta"/>
    <title>项目收款列表-目的地运营集团数据管理平台</title>
    <include file="Include:style"/>
    <style>
        .background {
            background: #f5f5f5;
        }
    </style>
</head>
<body>
<include file="Include:header"/>
<include file="Include:left"/>
<div id="main">
    <div class="crumbs">
        <div class="crumbs-text">项目收款列表</div>
        <div class="right">
            <a href="__APP__/ContractBack/back_excel/project_id/{$project_id}/back_status/{$back_status}"
               class="btn left mr5">导出Excel</a>
            <!--<if condition="$_SESSION['dms_permissions_id'] eq 1">
                <a href="__APP__/ContractBack/index_two" class="btn left mr5">更新老数据收款状态</a>
            </if>-->
        </div>
    </div>
    <div id="content">
        <div class="table-scrollx">
            <table class="table table-bordered">
                <tr class="table-header fixed-table-header">
                    <td width="350px">
                        <select name="project_id" class="form-control w400">
                            <option value=""
                            <if condition="$project_id eq null"> selected</if>
                            >项目编号-项目名称</option>
                            <foreach name="crm_project_array" item="vo">
                                <option value="{$vo['project_id']}"
                                <if condition="$project_id eq $vo['project_id']"> selected</if>
                                >{$vo['name']}</option>
                            </foreach>
                        </select>
                    </td>
                    <td width="">款项阶段</td>
                    <td width="">计划收款金额</td>
                    <td width="">实收金额</td>
                    <td width="">未收金额</td>
                    <td width="70">
                        <select name="back_status" class="form-control w90">
                            <option value="">收款状态</option>
                            <for start="1" end="4">
                                <option value="{$i}"
                                <if condition="$back_status eq $i"> selected</if>
                                >
                                <if condition="$i eq 1">
                                    已收
                                    <elseif condition="$i eq 2"/>
                                    未收
                                    <else/>
                                    部分收
                                </if>
                                </option>
                            </for>
                        </select></td>
                    <td width="70">
                        <select name="back_type" class="form-control w90">
                            <option value="">收款类型</option>
                            <for start="1" end="6">
                                <option value="{$i}"
                                <if condition="$back_type eq $i"> selected</if>
                                >
                                {:get_contract_back_type($i)}
                                </option>
                            </for>
                        </select></td>
                    <td width="">已开票金额</td>
                    <td width="">合同编号</td>
                    <td width="">计划收款日期</td>
                    <td width="">实际收款日期</td>
                   <!-- <td width="">添加人（日期）</td>-->
                    <td width="">操作</td>
                    </if>
                </tr>
                <if condition="$result eq NULL">
                    <tr>
                        <td class="text-center" colspan="13">暂无相关内容</td>
                    </tr>
                </if>
                <foreach name="result" item="v">
                    <foreach name="v" item="vo" key="key">
                        <tr>
                            <if condition="$key eq 0">
                                <td rowspan="{$v|count}"
                                    style="vertical-align: middle;"><a class="sk_btn" project_id="{$vo['project_id']}" href="javascript:;">{$vo['project_num']}-{$vo['name']}</a>
                                </td>
                            </if>
                            <td>{$vo['stage']}</td>
                            <td>{:float_money($vo['stage_money'])}</td>
                            <td>{:float_money($vo['money'])}</td>
                            <td>{:float_money($vo['stage_money']-$vo['money'])}</td>
                            <td>
                                <if condition="($vo['money'] gt 0) AND ($vo['money'] eq $vo['stage_money'])">
                                   <span class="label label-success">已收</span>  
                                    <elseif condition="($vo['money'] gt 0) AND ($vo['money'] lt $vo['stage_money'])"/>
                                    <span class="label label-warning">部分收</span>  
                                    <else/>
                                    <span class="label label-primary">未收</span>  
                                </if>
                            </td>
                            <td>{:get_contract_back_type($vo['type'])}</td>
                            <td>{:float_money($vo['make_money_sum'])}</td>
                            <td title="{$vo['contract_file_name']}">{$vo['contract_number']}</td>
                            <td>{$vo['stage_date']}</td>
                            <td>{$vo.date}</td>
                         <!--   <td>{:get_userName($vo['add_uid'])}({$vo['add_date']})</td>-->
                            <td class="nowrap">
                                <if condition="$vo['stage_money'] eq $vo['make_money_sum']">
                                    <a href="javascript:;"
                                       class="btn left mr5" style="background-color: grey" data-toggle="tooltip"
                                       data-placement="left" mid="320" data-original-title="此阶段发票金额已全部开完">开票</a>
                                    <else/>
                                    <a href="__APP__/ContractBack/add_invoice/back_id/{$vo['back_id']}"
                                       class="btn left mr5">开票</a>
                                </if>
                                <if condition="$vo['stage_money'] eq $vo['money']">
                                    <a href="javascript:;"
                                       class="btn left mr5" style="background-color: grey" data-toggle="tooltip"
                                       data-placement="left" mid="320" data-original-title="此阶段已全部收款完毕">添加收款</a>
                                    <else/>
                                    <a href="__APP__/ContractBack/add_receipt/back_id/{$vo['back_id']}"
                                       class="btn left mr5">添加收款</a>
                                </if>
                            </td>
                        </tr>
                    </foreach>
                </foreach>
                </if>
            </table>
        </div>
        <div class="pages">{$page}</div>
    </div>
</div>
<!--收款弹框-->
<div class="modal fade" id="sk-modal">
    <div class="modal-dialog w800">
        <div class="modal-content">
            <div class="modal-header">
                <h4>项目收款记录详情</h4>
                <i class="fa fa-times" aria-hidden="true" data-dismiss="modal"></i>
            </div>
            <div class="modal-body">

            </div>
        </div>
    </div>
</div>
<include file="Include:javascript"/>
<script>
    $(document).on("change", "[name='project_id']", function () {
        var val = $(this).val();
        window.location.href = "__APP__/ContractBack/index/project_id/" + val;
    });
    $(document).on("change", "[name='back_status']", function () {
        var val = $(this).val();
        window.location.href = "__APP__/ContractBack/index/back_status/" + val;
    });
    $(document).on("change", "[name='back_type']", function () {
        var val = $(this).val();
        window.location.href = "__APP__/ContractBack/index/back_type/" + val;
    });
    $(function () {
        $('.sk_btn').click(function () {
            $('#sk-modal .modal-body').html('');
            var project_id = $(this).attr("project_id");
            $.ajax({
                type: "GET",
                async: false,
                dataType: "json",
                data: {"project_id": project_id},
                url: "__APP__/ContractBack/get_contract_receipt",
                success: function (data) {
                    if (data) {
                        $('#sk-modal').modal();
                        var html = "<table class='table table-bordered'>";
                        html += "<tr class='table-header fixed-table-header'>";
                        html += "<td>合同编号</td><td>款项阶段</td><td>计划收款金额</td><td>发票编号</td><td>发票金额</td><td>收款金额</td>";
                        html += "</tr>";
                        for (var i = 0; i < data.length; i++) {
                            html += "<tr><td>" + data[i].contract_number + "</td><td>" + data[i].back_stage + "</td><td>" + data[i].back_stage_money + "</td><td>" + data[i].invoice_number + "</td><td>" + data[i].invoice_make_money + "</td><td>" + data[i].money + "</td></tr>";
                        }
                        html += "</table>";
                        $('#sk-modal .modal-body').html(html);
                    } else {
                        defeated_alert("暂无收款记录信息")
                    }
                }
            })
        })
    })
</script>
</body>
</html>